package com.ks.base;

import java.util.List;
import java.util.UUID;

import com.ks.util.ClassReflectUtil;

public abstract class BaseService<T> {

    public abstract BaseDao<T> getDao();

    public void add(T t) throws Exception {
        // 设置主键.字符类型采用UUID,数字类型采用自增
        ClassReflectUtil.setIdKeyValue(t, "id", UUID.randomUUID().toString());
        getDao().add(t);
    }

    public void update(T t) throws Exception {
        getDao().update(t);
    }

    public void updateBySelective(T t) {
        getDao().updateBySelective(t);
    }

    public void delete(Object... ids) throws Exception {
        if (ids == null || ids.length < 1) {
            return;
        }
        for (Object id : ids) {
            getDao().delete(id);
        }
    }

    public void del(Object o) throws Exception {
        getDao().delete(o);
    }

    public List<T> queryByList(Object o) throws Exception {

        return getDao().queryByList(o);
    }

    public int queryByCount(Object o) throws Exception {

        return getDao().queryByCount(o);
    }

    public List<T> queryList(Object o) {
        // TODO Auto-generated method stub
        return getDao().queryList(o);
    }

    public T queryById(Object id) throws Exception {
        return getDao().queryById(id);
    }
}
